//
//  HideCellViewController.m
//  20170207
//
//  Created by xuPeng on 2017/9/22.
//  Copyright © 2017年 一直丶黑曼巴. All rights reserved.
//

#import "HideCellViewController.h"
#import "MIDMainViewController.h"

@interface HideCellViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong)UITableView *tabelView;
@property (nonatomic, strong)NSMutableArray *array;
@end

@implementation HideCellViewController
- (UITableView *)tabelView{
    if (!_tabelView) {
        _tabelView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
        _tabelView.delegate = self;
        _tabelView.dataSource = self;
        _tabelView.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];
        [_tabelView setSeparatorColor:[UIColor orangeColor]];
//        _tabelView.separatorStyle = UITableViewCellSelectionStyleNone;
        if ([_tabelView respondsToSelector:@selector(setSeparatorInset:)]) {
            [_tabelView setSeparatorInset:UIEdgeInsetsMake(50, 50, 0, 50)];
        }
//        西安鸟市西仓
    }
    return _tabelView;
}

- (NSMutableArray *)array{
    if (!_array) {
//        NSArray *aar = @[];
        _array = [[NSMutableArray alloc] initWithObjects:@"1",@"1",@"1",@"1",@"1"@"1",@"1",@"1", nil];
    }
    return _array;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    // 如果是你需要隐藏的那一行，返回高度为0
    if(indexPath.row == 2){
        return 0;
    }else{
        return 44;

    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, 0, 100, 50);
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btn setTitle:@"Show Again" forState:UIControlStateNormal];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
    [btn addTarget:self action:@selector(loadData) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.tabelView];
}
- (void)loadData{

    // 切换根视图控制器
    [UIView transitionWithView:[UIApplication sharedApplication].keyWindow duration:0.5f options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
        BOOL oldState = [UIView areAnimationsEnabled];
        [UIView setAnimationsEnabled:NO];
        [UIApplication sharedApplication].keyWindow.rootViewController = [MIDMainViewController new];
        [UIView setAnimationsEnabled:oldState];
    } completion:^(BOOL finished) {
    }];
}
- (void)viewWillAppear:(BOOL)animated{
    self.tabBarController.tabBar.hidden = YES;
}
- (void)viewWillDisappear:(BOOL)animated{
    self.tabBarController.tabBar.hidden = NO;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.array.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellName = @"cell";
    UITableViewCell *cell = [_tabelView dequeueReusableCellWithIdentifier:cellName];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
        
    }
    cell.textLabel.text = [NSString stringWithFormat:@"%ld",(long)indexPath.row];
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//    if (indexPath.row == 5) {
//        [self.tabelView beginUpdates];
//    }else  if (indexPath.row == 6) {
//        [self.tabelView endUpdates];
//    }
}



- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
  //（据说）必须写的方法，和editActionsForRowAtIndexPath配对使用，要不然在iOS8中不可滑动
}

- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath

{
    
    UITableViewRowAction *layTopRowAction1 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"收藏" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
            NSLog(@"已将收藏");
        tableView.editing = NO;
        
    }];
    UITableViewRowAction *layTopRowAction2 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"删除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
        
        NSLog(@"即将删除本行啦。。。");
        [_array removeObjectAtIndex:indexPath.row];
//         [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];//移除tableView中的数据
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];

    }];
    layTopRowAction1.backgroundColor = [UIColor redColor];
    layTopRowAction2.backgroundColor = [UIColor orangeColor];
    NSArray *arr = @[layTopRowAction1,layTopRowAction2];
    return arr;
}










@end
